package com.design.fitment.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioGroup;

import com.design.fitment.R;
import com.design.fitment.fragment.FoundFragment;
import com.design.fitment.fragment.GalleryActivity;
import com.design.fitment.fragment.MainFragment;
import com.design.fitment.fragment.MineFragment;
import com.design.fitment.fragment.QuestionsAnswersFragment;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;

@ContentView(R.layout.activity_main)
public class MainActivity extends AppCompatActivity {
    private FragmentManager mFragmentManger;
    private FragmentTransaction mTransaction;
    @ViewInject(R.id.rg_main)
    public RadioGroup rg_main;
    @ViewInject(R.id.ll_main)
    private LinearLayout mLl_main;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        ViewUtils.inject(this);
        initMainPage();
    }

    private void initMainPage() {
        mFragmentManger = getSupportFragmentManager();

        rg_main.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
                mTransaction = mFragmentManger.beginTransaction();
                switch (checkedId) {
                    case R.id.btn_main_case:
                        mTransaction.replace(R.id.fl_main_content, new MainFragment());
                        mTransaction.commit();
                        break;
                    case R.id.btn_main_found:
                        mTransaction.replace(R.id.fl_main_content, new FoundFragment());
                        mTransaction.commit();
                        break;
                    case R.id.btn_main_mine:
                        mTransaction.replace(R.id.fl_main_content, new MineFragment());
                        mTransaction.commit();
                        break;
                    case R.id.btn_main_answers:
                        mTransaction.replace(R.id.fl_main_content, new QuestionsAnswersFragment());
                        mTransaction.commit();
                        break;
                    case R.id.btn_main_pictrue:
                        mTransaction.replace(R.id.fl_main_content, new GalleryActivity());
                        mTransaction.commit();
                        break;
                }

            }
        });
        View v = rg_main.getChildAt(0);//获得radiogroup下的第一个子控件
        v.performClick();//模拟点击事件

    }
}
